package org.chen.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.chen.common.system.province.Attraction;
import org.chen.common.system.province.ProvinceCapital;

import java.util.List;

@Mapper
public interface AttractionMapper extends BaseMapper<Attraction> {

    @Select("SELECT a.*, pc.name, pc.ctrip_city_id, pc.tongcheng_city_id, pc.mafengwo_city_id as capitalName FROM system_attraction a " +
            "LEFT JOIN system_province_capital pc ON a.province_capital_id = pc.id " +
            "WHERE a.province_capital_id = #{capitalId}")
    List<Attraction> getAttractionsByCapitalId(Long capitalId);

    @Select("SELECT pc.* FROM system_province_capital pc " +
            "JOIN system_attraction a ON pc.id = a.province_capital_id " +
            "WHERE a.name = #{attractionName}")
    ProvinceCapital findCapitalIdByAttractionName(String attractionName);

    // 根据平台和ID查找省会城市ID
    @Select("<script>" +
            "SELECT * FROM system_province_capital WHERE " +
            "<choose>" +
            "<when test='platform == \"ctrip\"'>ctrip_city_id = #{platformId}</when>" +
            "<when test='platform == \"tongcheng\"'>tongcheng_city_id = #{platformId}</when>" +
            "<when test='platform == \"mafengwo\"'>mafengwo_city_id = #{platformId}</when>" +
            "</choose>" +
            "</script>")
    ProvinceCapital findCapitalIdByPlatformId(@Param("platform") String platform, @Param("platformId") String platformId);

    // 根据平台和ID查找景点对应的省会城市ID
    @Select("<script>" +
            "SELECT pc.* FROM system_province_capital pc " +
            "JOIN system_attraction a ON pc.id = a.province_capital_id WHERE " +
            "<choose>" +
            "<when test='platform == \"ctrip\"'>a.ctrip_id = #{platformId}</when>" +
            "<when test='platform == \"tongcheng\"'>a.tongcheng_id = #{platformId}</when>" +
            "<when test='platform == \"mafengwo\"'>a.mafengwo_id = #{platformId}</when>" +
            "</choose>" +
            "</script>")
    ProvinceCapital findCapitalIdByAttractionPlatformId(@Param("platform") String platform, @Param("platformId") String platformId);
}